/**
 * 
 */
package com.cqcis.uip.module.salary.oper.dao;

import java.util.List;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.cqcis.uip.base.framework.utils.JdbcUtil;
import com.cqcis.uip.base.framework.utils.TimeUtil;
import com.cqcis.uip.module.salary.oper.domain.Contract;

/**
 * @author 李世军
 *
 * 创建于 2012-3-7 下午08:16:53
 */
public class ContractDao extends JdbcDaoSupport {
	private static String FIELDS = " id ,student_id ,service_fee ,education_fee ,traffic_fee ,service_fee_pay ,education_fee_pay ,traffic_fee_pay ,begin_time ,end_time ,finish_time ,contract_type ,state  ";
	private static String SELECT_SQL = " select "+FIELDS+" from customercontrol_trainingcontract where state in(1,4) and finish_time>=? and finish_time<=? ";
	private static String FINISH_SQL = " update  customercontrol_trainingcontract set end_time=now(), state=4, remark=CONCAT(remark,'|系统自动归档') where now()>=end_time  and state=1  " ;
	
	/**
	 * 查询所有合同
	 * @param state(状态 0预制，1有效，2主管待审核,3财务待审核 ,4归档,5财务驳回,6主管驳回) 
	 * @return
	 */
    public List<Contract> find() {
    	return JdbcUtil.queryForList(this, Contract.class, SELECT_SQL, getStartDate(), getEndDate());
    }
    
    /**
     * 合同归档
     */
    public void finishContract(){
    	JdbcUtil.update(this, FINISH_SQL) ;
    }
    
    private String getStartDate(){
		return TimeUtil.getCurrentTimeStr("yyyy-MM")+"-01" ;
	}
	
	private String getEndDate(){
		return TimeUtil.getCurrentTimeStr("yyyy-MM")+"-31" ;
	}
}
